﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Yunzuan.Foundation.Web.Pages
{
    public class BaseManagePage : System.Web.UI.Page
    {
        #region 基础Session信息

        #region Const

        private static readonly string SESSION_NAME_ADMIN_USER_ID = "UserID";
        private static readonly string SESSION_NAME_ADMIN_USER_NAME = "UserAccount";
        private static readonly string SESSION_NAME_ADMIN_REAL_NAME = "UserRealName";

        #endregion

        #region AdminUserID

        private int? _adminUserID;
        public int UserID
        {
            get
            {
                if (!_adminUserID.HasValue)
                {
                    _adminUserID = SessionManager.GetSession<int>(SESSION_NAME_ADMIN_USER_ID);
                }
                return _adminUserID.Value;
            }
            set
            {
                _adminUserID = value;
                SessionManager.SetSession(SESSION_NAME_ADMIN_USER_ID, value);
            }
        }

        #endregion

        #region AdminUserName

        private string _adminUserName;
        public string UserAccount
        {
            get
            {
                if (string.IsNullOrEmpty(_adminUserName))
                {
                    _adminUserName = SessionManager.GetSession(SESSION_NAME_ADMIN_USER_NAME);
                }
                return _adminUserName;
            }
            set
            {
                _adminUserName = value;
                SessionManager.SetSession(SESSION_NAME_ADMIN_USER_NAME, value);
            }
        }

        #endregion

        #region AdminRealName

        private string _adminRealName;
        public string UserRealName
        {
            get
            {
                if (string.IsNullOrEmpty(_adminRealName))
                {
                    _adminRealName = SessionManager.GetSession(SESSION_NAME_ADMIN_REAL_NAME);
                }
                return _adminRealName;
            }
            set
            {
                _adminRealName = value;
                SessionManager.SetSession(SESSION_NAME_ADMIN_REAL_NAME, value);
            }
        }

        #endregion

        #endregion

        public bool IsLogin()
        {
            return this.UserID > 0;
        }
    }
}
